package com.vue.controller.teacher;

import com.vue.context.BaseContext;
import com.vue.dto.CourseDTO;
import com.vue.dto.CoursePageQueryDTO;
import com.vue.result.PageResult;
import com.vue.result.Result;
import com.vue.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("teacherCourseController")
@RequestMapping("/teacher/course")
@Api(tags = "课程相关接口")
@Slf4j
public class CourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 课程分页查询
     * @param coursePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("课程分页查询")
    public Result<PageResult> coursePage(CoursePageQueryDTO coursePageQueryDTO) {
        log.info("课程分页查询：{}", coursePageQueryDTO);
        Long id = BaseContext.getCurrentId();
        coursePageQueryDTO.setTeacherId(id);
        PageResult pageResult = courseService.PageQuery(coursePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增课程
     * @param courseDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增课程")
    public Result add(@RequestBody CourseDTO courseDTO) {
        log.info("新增课程：{}", courseDTO);
        courseService.add(courseDTO);
        return Result.success();
    }

    /**
     * 修改课程
     * @param courseDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改课程")
    public Result update(@RequestBody CourseDTO courseDTO) {
        log.info("修改课程: {}", courseDTO);
        courseService.update(courseDTO);
        return Result.success();
    }

    /**
     * 根据id删除课程
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除课程")
    public Result deleteCourse(@PathVariable Long id) {
        log.info("根据id删除课程：{}", id);
        courseService.deleteCourse(id);
        return Result.success();
    }
}
